package com.jsgt.greekfire.common.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.SeekBar;

import androidx.appcompat.widget.AppCompatSeekBar;

public class BubbleSeekBar extends AppCompatSeekBar {
	private Drawable mThumbDrawable;
	private BubbleIndicator mBubbleIndicator;
	public BubbleSeekBar(Context context) {
		this(context, null);
	}

	public BubbleSeekBar(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public BubbleSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		mBubbleIndicator = new BubbleIndicator(context, attrs, defStyleAttr, "100");
		setOnSeekBarChangeListener(mOnSeekBarChangeListener);
	}



    @Override
    public void setThumb(Drawable thumb) {
        super.setThumb(thumb);
        mThumbDrawable = thumb;
    }
	  
	private OnSeekBarChangeListener mOnSeekBarChangeListener = new OnSeekBarChangeListener() {
		
		@Override
		public void onStopTrackingTouch(SeekBar seekBar) {
			//mBubbleIndicator.hideIndicator();
			mBubbleIndicator.showIndicator(seekBar, mThumbDrawable.getBounds());
		}
		
		@Override
		public void onStartTrackingTouch(SeekBar seekBar) {
			mBubbleIndicator.showIndicator(seekBar, mThumbDrawable.getBounds());
		}
		
		@Override
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			if(fromUser)
				mBubbleIndicator.moveIndicator(mThumbDrawable.getBounds(), progress);
		}
	};
}
